import process from 'node:process'
import { defineConfig } from 'vitepress'
import { withPwa } from '@vite-pwa/vitepress'
import { generateSitemap as sitemap } from 'sitemap-ts'
import { description, github, keywords, name, site } from './meta'
import { genFeed } from './plugins/genFeed'
import { pwa } from './plugins/pwa'
import sidebar from './sidebar'
import socialLinks from './link'

export default withPwa(defineConfig({
  pwa,
  outDir: '../dist',
  title: name,
  description,
  lastUpdated: true,
  useWebFonts: false,
  markdown: {
    lineNumbers: false,
  },
  locales: {
    root: { label: '简体中文', lang: 'zh-CN' },
  },
  themeConfig: {
    logo: '/logo.png',
    outline: {
      label: '导航栏',
      level: 'deep',
    },
    docFooter: {
      prev: '上一篇',
      next: '下一篇',
    },
    returnToTopLabel: '返回顶部',
    darkModeSwitchLabel: '外观',
    sidebarMenuLabel: '归档',
    lastUpdated:{
      text: '最后一次更新于',
    },
    footer: {
      message: `用心去做高质量开源项目，欢迎 <a target="_blank" style="color: var(--vp-c-brand)" href="${github}">star ⭐</a> 让更多人发现`,
      copyright: `<a target="_blank" href="${github}/blob/master/LICENSE">Apache License</a> | 版权所有 © 2022-${new Date().getFullYear()} <a target="_blank" href="${github}"> WEMIRR-PLATFORM</a>`,
    },
    nav: [
      {
        text: "📋 帮助文档", link: "/zh/guide/index"
      },
      {text: '🆘 常见问题', link: '/zh/faq/'},
      {
        text: '🔥 商业版', link: '/zh/business/'
      },
      {text: '💭 生态市场', link: '/zh/market/'},
      {text: '联系我们', link: 'https://gitee.com/battcn/'},
      {text: '问题反馈', link: 'https://gitee.com/battcn/wemirr-platform/issues'},
    ],
    search:{
      provider: 'local',
      options:{
        detailedView: true,
        translations:{
          button:{
            buttonText: '搜索文档',
            buttonAriaLabel: '搜索文档'
          },
          modal: {
            noResultsText: '无法找到相关结果',
            resetButtonTitle: '清除查询条件',
            footer: {
              selectText: '选择',
              closeText: '关闭',
              navigateText: '切换'
            }
          }
        }
      }
    },
    sidebar,
    socialLinks,
  },
  head: [
    ['meta', { name: 'referrer', content: 'no-referrer-when-downgrade' }],
    ['meta', { name: 'keywords', content: keywords }],
    ['meta', { property: 'og:type', content: 'article' }],
    ['meta', { name: 'application-name', content: name }],
    ['meta', { name: 'apple-mobile-web-app-title', content: name }],
    ['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'default' }],

    ['link', { rel: 'shortcut icon', href: '/favicon.ico' }],
    ['link', { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
    ['meta', { name: 'theme-color', content: '#06f' }],
    // og
    ['meta', { property: 'og:description', content: description }],
    ['meta', { property: 'og:url', content: site }],
    ['meta', { property: 'og:locale', content: 'zh_CN' }],
    // analytics
    ['script', { 'async': '', 'defer': '', 'data-website-id': `${process.env.UMAMI_WEBSITE_ID || ''}`, 'src': `${process.env.UMAMI_ENDPOINT || ''}` }],
  ],
  async buildEnd(siteConfig) {
    await sitemap({ hostname: 'https://docs.battcn.com/' })
    await genFeed(siteConfig)
  },
}))

